/*
 * @Author: 枫林 670979892@qq.com
 * @Date: 2025-02-01 10:44:28
 * @LastEditors: 枫林 670979892@qq.com
 * @LastEditTime: 2025-02-04 16:43:25
 * @FilePath: \undefinedd:\user\Desktop\deepseek.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

import OpenAI from "openai";
const Url = "https://api.deepseek.com"; //DeepSeek API 地址
const Authentication = "<DeepSeek API Key>"; //密钥
const Model = "deepseek-chat"; //模型
const System_Prompt = ""; //预设的对话内容，可以为空
const Temperature = 1.3; //温度
const List = []; //敏感词列表，可以为空

export class deepseekAI extends plugin {
  constructor() {
    super({
      name: 'deepseekAI',
      event: 'message',
      priority: 200,
      rule: [
        {
          reg: '^#chat([\\s\\S]*)$',
          fnc: 'chat',
        }
      ]
    })
  }

  async chat(e) {
    let msg = e.msg; 
    msg = msg.replace('#chat', '');
    if (!msg) {e.reply('请输入内容');return false;};
    if (msg.length > 50) {e.reply('输入文本长度过长');return true;};
    if (List.some(item => msg.includes(item))) {
      logger.info(`[deepseekAI]检测到敏感词，已过滤`);
      e.reply("输入包含敏感词，已拦截");
      return true;
    };

    const openai = new OpenAI({
      baseURL: Url,
      apiKey: Authentication
    });
    const completion = await openai.chat.completions.create({
      messages: [
        { role: "system",  content: `${System_Prompt}` },
        { role: "user", content: `${msg}` }
      ],
      temperature: Temperature,
      stream: false,
      model: Model,
    });
    const content = completion.choices[0].message.content;
    
    if (List.some(item => content.includes(item))) {
      logger.info(`[deepseekAI]检测到输出包含敏感词，已过滤：${content}`);
      e.reply("输出包含敏感词，已拦截");
      return true;
    };
    logger.info(content);
    e.reply(content);
    return true;
  }
}
